package com.qf.mrmd.controller;

import com.qf.mrmd.entity.Pic;
import com.qf.mrmd.result.ResponseCode;
import com.qf.mrmd.result.ResponseData;
import com.qf.mrmd.service.PicService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController     //组合注解，表名下面类中的所有都是控制层并且返回为json格式
@RequestMapping("pics")   //路径映射
@Api("picApis")    //接口注解
public class PicController {

    @Autowired  //自动装配
    private PicService picService;                //服务层的接口对象


        /**
         *  模拟完整的添加操作
         *  1、http://localhost:8080/pics/    ---POST
         *  2、{"title":"轮播","url":"http://localhost:8080/img/a.jpg","type":"lb"}
         *  3、ResponseData   {ecode:"",info:"",data:""}
         *
         */
        @ApiOperation(value = "保存图片信息")//swagger???
        @PostMapping("/")
        public ResponseData savePicInfo(@RequestBody Pic pic){
            return picService.savePicInfo(pic);

        }

        @GetMapping("{/id}")
        @ApiImplicitParam(name = "id")
        @ApiOperation(value = "查询id")
        public ResponseData query(@RequestBody Integer id){
            Pic pic = picService.queryById(id);
            return new ResponseData(ResponseCode.SUCCESS,pic);
        }

        @PostMapping("/v")
        @ApiOperation(value = "保存数据信息")
        public ResponseData saveData(@RequestBody Pic pic){
            return picService.saveData(pic);
        }

        @ApiOperation(value = "获取轮播或者导航图片",notes = "通过图片的类型获取对应的图片列表")
        @ApiImplicitParam(name = "type",value = "图片的类型",dataType = "string")
        @GetMapping("/all/{type}")  //获取图片信息
        public ResponseData picInfo(@PathVariable String type){
           return picService.queryByType(type);

        }
//查询所有图片
        @ApiOperation(value = "查询所有图片",notes = "通过图片的id查询所有的图片")
        @ApiImplicitParam(name = "id",value = "图片的id",dataType = "integer")
        @GetMapping("/allpic/{id}")
        public ResponseData queryAllInfo(@PathVariable Integer id){
            return picService.queryallpicById(id);
        }
//删除图片
        @ApiOperation(value = "删除图片",notes = "通过图片的id删除图片")
        @GetMapping("/del/{id}")
        @ApiImplicitParam(name = "id",value = "图片的id",dataType = "integer")
        public ResponseData deleteByid(@PathVariable Integer id){
            return picService.deleById(id);
        }
//插入图片
        @ApiOperation(value = "插入图片")
        @ApiImplicitParam(name = "title",value = "根据图片的title插入")
        @PostMapping("/insertPic")
        public ResponseData insertPic(@RequestBody Pic pic){
            return picService.insertPic(pic);
        }
//修改图片信息
        @ApiOperation(value = "修改图片信息")
        @ApiImplicitParam(name = "id",value = "根据图片的id修改")
        @PostMapping("/UpdatePic")
        public ResponseData updatePic(@RequestBody Pic pic){
            return picService.updatePic(pic);
        }


}
